home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
objtools
/
totri.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
2KB
|
116 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* totri -
* Convert an object to triangles.
*
* Paul Haeberli - 1990
*/
#include "math.h"
#include "stdio.h"
#include "vect.h"
#include "sgiobj.h"
sgiobj *sgototri();
main(argc,argv)
int argc;
char **argv;
{
sgiobj *obj;
if(argc<3) {
fprintf(stderr,"usage: totri in.sgo out.sgo [-randord]\n");
exit(1);
}
obj = readsgiobj(argv[1]);
if(argc>=3)
obj = sgototri(obj,1);
else
obj = sgototri(obj,0);
writesgiobj(argv[2],obj);
exit(0);
}
int count;
countfunc()
{
count++;
}
float *fptr;
int *ordtab;
copytri(p0,p1,p2)
float *p0, *p1, *p2;
{
float *dptr;
dptr = fptr + ordtab[count]*(3*PNTLONGS);
bcopy(p0,dptr,PNTLONGS*sizeof(long));
dptr+= PNTLONGS;
bcopy(p1,dptr,PNTLONGS*sizeof(long));
dptr+= PNTLONGS;
bcopy(p2,dptr,PNTLONGS*sizeof(long));
count++;
}
randorder(tab,len)
int tab[];
{
int i, pos, temp;
if(len<2)
return;
srandom(getpid());
for(i=0; i<len; i++) {
pos = i+random()%(len-i);
temp = tab[pos];
tab[pos] = tab[i];
tab[i] = temp;
}
}
sgiobj *sgototri(obj,randord)
sgiobj *obj;
int randord;
{
sgiobj *tobj;
int i;
if((randord == 0) && obj->objtype == OBJ_TRILIST)
return clonesgiobj(obj);
count = 0;
applytotris(obj,countfunc);
ordtab = (int *)malloc(count*sizeof(int));
for(i=0; i<count; i++)
ordtab[i] = i;
if(randord)
randorder(ordtab,count);
tobj = (sgiobj *)newtriobj(count);
fptr = (float *)tobj->data;
count = 0;
applytotris(obj,copytri);
free(ordtab);
return tobj;
}